<?php get_header(); ?>
<?php
    $city_name = get_city();
?>
<script type="text/javascript">
var city_name = '<?php echo $city_name; ?>';
</script>
<div class="grid_16" style="height: 30px; border: 1px solid; margin-top: 20px; display:none;"></div>
<!--Slider-->
<div class="grid_12 home_wrap"> 
  <div id="featured">
  <ul class="ui-tabs-nav">
    <li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1"><a href="#fragment-1"></a></li>
    <li class="ui-tabs-nav-item" id="nav-fragment-2"><a href="#fragment-2"></a></li>
    <li class="ui-tabs-nav-item" id="nav-fragment-3"><a href="#fragment-3"></a></li>
    <li class="ui-tabs-nav-item" id="nav-fragment-4"><a href="#fragment-4"></a></li>
    <li class="ui-tabs-nav-item" id="nav-fragment-5"><a href="#fragment-5"></a></li>
  </ul>
  <?php
    $slider_deal = new Pod('deal');
    $slider_deal->page = 1;
    $slider_deal->search = false;
    $slider_deal->findRecords('id DESC', 5, 't.slider = 1 && t.camp_end > '.fix_date());
    $count = 0;
    while ($slider_deal->fetchRecord()){
    $count++;
    $tags_deal = get_deal_tags($slider_deal);
    $deal_link = BUZZR_URL.'/deals/'.$slider_deal->get_field('camp_link');
    $deal_name = $slider_deal->get_field('name');
    $deal_title = substr($deal_name,0,150);
    $deal_detail = substr($slider_deal->get_field('short'),0,150).'...<a href="'.$deal_link.'" title="'.$deal_name.'">more</a>';
    
    $image = $slider_deal->get_field('image');
    $full_image = wp_get_attachment_image_src($image[0][ID], 'large', false);
    $deal_image = $full_image[0];
  ?>
  	
  <div id="fragment-<?php echo $count; ?>" class="ui-tabs-panel">
	 <div id="fragment_img_<?php echo $count; ?>" class="fragment_img"><img src="<?php echo $deal_image; ?>" alt="<?php echo $tags_deal; ?>" /></div>
	 <div id="info_<?php echo $count; ?>" class="info">
		<h2><a href="<?php echo $deal_link; ?>"><?php echo $deal_title; ?></a></h2>
		<p><?php echo $deal_detail; ?></p>
	 </div>
  </div>		
	
  <?php } ?>
			
	</div>
  
</div>
<!-- Slider End -->

<!-- Special Offers -->
<div class="grid_4 home_wrap">

<div id="special_offers">
	<a title="Buzzr iPhone App" href="<?php echo BUZZR_URL.'/mobile'; ?>"><img alt="buzzr-iphone" src="<?php echo BUZZR_WP_URL.'/wp-content/pfiles/images/iphone-app.jpg'; ?>" /></a>
</div>

<div class="clear"></div>

<div id="special_offers"> 
	<a title="Get the Best Coupons, Discounts" href="<?php echo BUZZR_URL.'/coupons'; ?>"><img alt="coupons" src="<?php echo BUZZR_WP_URL.'/wp-content/pfiles/images/coupons-promo.jpg'; ?>" /></a>
</div>

<div class="clear"></div>
 
<div id="special_offers">
	<a title="Check out the Daily Deals from all Cities" href="<?php echo BUZZR_URL.'/dailydeals'; ?>"><img alt="daily-offers" src="<?php echo BUZZR_WP_URL.'/wp-content/pfiles/images/dailydeals-promo.jpg'; ?>" /></a>
</div>



<div class="clear"></div>
</div>

<div class="clear"></div>
<!-- Special Offers Ends -->

<!-- Nation Wide Deals -->
<div id="nationwide_deals" class="grid_8 home_wrap">
  <h3>Nationwide Deals</h3>
  <div id="nationwide_tabbed" class="tabbed">
	<ul class="tabs">
		<li class="t1"><a class="t1 tab" title="Latest Deals">Latest Deals</a></li>
		<li class="t2"><a class="t2 tab" title="Popular Deals">Popular Deals</a></li>
		<li class="t3"><a class="t3 tab" title="Featured Deals">Featured Deals</a></li>
	</ul>
	<div class="clear"></div>

  <!-- Latest Deals --> 
  <div id="t1" class="t1">

  <?php
    $latest_deal = new Pod('deal');
    $latest_deal->page = 1;
    $latest_deal->search = false;
    $latest_deal->findRecords('id DESC', 8, 't.sale = 0  && t.camp_end > '.fix_date());
    $count = 0;
    while ($latest_deal->fetchRecord()){
	    $deal_link_ga = get_redirect($latest_deal);
	    $merchant_name = ucwords($latest_deal->get_field('brand.name'));
	    $tags_deal = get_deal_tags($latest_deal);
	    $deal_id = $latest_deal->get_field('id');
	    $deal_link = BUZZR_URL.'/deals/'.$latest_deal->get_field('camp_link');
	    $deal_name = $latest_deal->get_field('name');
	    $deal_title = substr($deal_name,0,150);
	    $image_latest = get_image($latest_deal);
	    $is_coupon = $latest_deal->get_field('coupon');
  ?>
      	<div id="latest_deal_wrap_<?php echo $deal_id; ?>" class="deal">
            
            <div id="latest_deal_image_wrap_<?php echo $deal_id; ?>" class="deal_image">
                <?php if($image != TRUE){ ?>
                <a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><div class="image_filler_home"><p><?php echo $merchant_name;?></p></div></a>
                <?php }else{ ?>
               	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><img src="<?php echo $image_latest; ?>" alt="<?php echo $tags_deal; ?>" /></a>
               	<?php } ?>
            </div>
            <div id="latest_deal_detail_wrap_<?php echo $deal_id; ?>" class="deal_detail">
            	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><?php echo $deal_title; ?></a>
            </div>
        
        </div>
        
   	<?php } ?>   
        
	</div>
	
	
	<!-- Latest Deals End-->
    
	<!-- Popular Deal -->
	<div id="t2" class="t2">
	<?php
    $popular_deal = new Pod('deal');
    $popular_deal->page = 1;
    $popular_deal->search = false;
    $popular_deal->findRecords('id DESC', 8, 't.slider = 1 && t.camp_end > '.fix_date());
    $count = 0;
    while ($popular_deal->fetchRecord()){
    	$deal_link_ga = get_redirect($popular_deal);
	    $merchant_name = ucwords($popular_deal->get_field('brand.name'));
	    $tags_deal = get_deal_tags($popular_deal);
	    $deal_id = $popular_deal->get_field('id');
	    $deal_link = BUZZR_URL.'/deals/'.$popular_deal->get_field('camp_link');
	    $deal_name = $popular_deal->get_field('name');
	    $deal_title = substr($deal_name,0,150);
	    $image_popular = get_image($popular_deal);
	    $is_coupon = $popular_deal->get_field('coupon');
    ?>
      	<div id="popular_deal_wrap_<?php echo $deal_id; ?>" class="deal">
            
            <div id="popular_deal_image_wrap_<?php echo $deal_id; ?>" class="deal_image">
            	<?php if($image != TRUE){ ?>
                <a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><div class="image_filler_home"><p><?php echo $merchant_name;?></p></div></a>
                <?php }else{ ?>
               	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><img src="<?php echo $image_popular; ?>" alt="<?php echo $tags_deal; ?>" /></a>
               	<?php } ?>
            </div>
            <div id="popular_deal_detail_wrap_<?php echo $deal_id; ?>" class="deal_detail">
            	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><?php echo $deal_title; ?></a>
            </div>
        
        </div>
        
	<?php } ?>
        
 	</div>
   <!-- Popular Deal End -->
   
	<!-- Featured Deal -->
	<div class="t3" id="t3"> 
	<?php
    $featured_deal = new Pod('deal');
    $featured_deal->page = 1;
    $featured_deal->search = false;
    $featured_deal->findRecords('id DESC', 8, 't.exclusive = 1 && t.camp_end > '.fix_date());
    $count = 0;
    while ($featured_deal->fetchRecord()){
    	$deal_link_ga = get_redirect($featured_deal);
    	$merchant_name = ucwords($featured_deal->get_field('brand.name'));
	    $tags_deal = get_deal_tags($featured_deal);
	    $deal_id = $featured_deal->get_field('id');
	    $deal_link = BUZZR_URL.'/deals/'.$featured_deal->get_field('camp_link');
	    $deal_name = $featured_deal->get_field('name');
	    $deal_title = substr($deal_name,0,150);
	    $image_featured = get_image($featured_deal);
	    $is_coupon = $popular_deal->get_field('coupon');
  ?>
      	<div id="featured_deal_wrap_<?php echo $deal_id; ?>" class="deal">         
            <div id="featured_deal_image_wrap_<?php echo $deal_id; ?>" class="deal_image">
                <?php if($image != TRUE){ ?>
                <a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><div class="image_filler_home"><p><?php echo $merchant_name;?></p></div></a>
                <?php }else{ ?>
               	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><img src="<?php echo $image_featured; ?>" alt="<?php echo $tags_deal; ?>" /></a>
               	<?php } ?>
            </div>
            <div id="featured_deal_detail_wrap_<?php echo $deal_id; ?>" class="deal_detail">
            	<a <?php buzzr_follow(); ?> href="<?php if($is_coupon == 1){ echo $deal_link; }else { echo $deal_link_ga; } ?>"><?php echo $deal_title; ?></a>
            </div>        
        </div>
        
    <?php } ?>
	
	</div>
	<!-- Featured Deal End -->

  </div>
  <div class="grid_8 more_deals t1">
       	<p>Show more <a href="<?php echo BUZZR_URL.'/deals'; ?>">Latest Deals</a></p>
  </div>
  <div class="grid_8 more_deals t2">
  		<p>Show more <a href="<?php echo BUZZR_URL.'/deals-popular'; ?>">Popular Deals</a></p>   	
  </div>
  <div class="grid_8 more_deals t3">
       	<p>Show more <a href="<?php echo BUZZR_URL.'/deals'; ?>">Featured Deals</a></p>
  </div>
</div>  
<!-- Nation Wide Deals Ends -->

<!-- Local Deals -->
<div id="local_deals" class="grid_8 home_wrap">
  <?php if(!empty($city_name)){?>
  <h3>Deals in <?php echo $city_name; ?></h3>
  <?php } else {?>
  <h3>Deals in Mumbai</h3>
  <?php }?>
  <div id="local_tabbed" class="tabbed1">

	<ul class="tabs">
		<li class="t4"><a class="t4 tab" title="Map View">Map View</a></li>
		<li class="t5"><a class="t5 tab" title="List View">List View</a></li>
		<li class="t6"><a class="t6 tab" title="Coupons">Coupons</a></li>
	</ul>

	<!-- Map View -->
	<div class="t4" id="t4">
	     	<div id="map_canvas"></div>
			<div id="details"></div>
			<div id="spinner"><img src="<?php echo BUZZR_THEME_URL.'/img/buzzr_spinner.gif'; ?>" /></div>
	</div>
	<!-- Map View End -->

	<!-- List View -->
	<div id="t5" class="t5">
	<?php
    $list_view = new Pod('deal');
    $list_view->page = 1;
    $list_view->search = false;
    $list_view->findRecords('id DESC', 8, "t.sale = 1 && city.name='$city_name' && t.camp_end > ".fix_date());
    $count = 0;
    while ($list_view->fetchRecord()){
    $deal_link_ga = get_redirect($list_view);
    $merchant_name = ucwords($list_view->get_field('brand.name'));
    $tags_deal = get_deal_tags($list_view);
    $deal_id = $list_view->get_field('id');
    $deal_link = BUZZR_URL.'/deals/'.$list_view->get_field('camp_link');
    $deal_name = $list_view->get_field('name');
    $deal_title = substr($deal_name,0,150);
    $image_list = get_image($list_view);
  ?>
      	<div id="latest_city_wrap_<?php echo $deal_id; ?>" class="deal">
            
            <div id="latest_city_image_wrap_<?php echo $deal_id; ?>" class="deal_image">
               <?php if($image_list != TRUE){ ?>
               <a <?php buzzr_follow(); ?> href="<?php echo $deal_link_ga; ?>"><div class="image_filler_home"><p><?php echo $merchant_name;?></p></div></a>
               <?php }else{ ?>
               <a <?php buzzr_follow(); ?> href="<?php echo $deal_link_ga; ?>"><img src="<?php echo $image_list; ?>" alt="<?php echo $tags_deal; ?>" /></a>
               <?php } ?>
            </div>
            <div id="latest_city_detail_wrap_<?php echo $deal_id; ?>" class="deal_detail">
            	<a <?php buzzr_follow(); ?> href="<?php echo $deal_link_ga; ?>"><?php echo $deal_title; ?></a>
            </div>
        
        </div>
        
    <?php } ?>
	
	</div>
  	<!-- List View -->
  	
  	<!-- Coupons -->
	<div id="t6" class="t6">
	<?php
    $coupon_view = new Pod('deal');
    $coupon_view->page = 1;
    $coupon_view->search = false;
    $coupon_view->findRecords('id DESC', 8, "t.coupon = 1 && t.sale = 1 && city.name='$city_name' && t.camp_end > ".fix_date());
    while ($coupon_view->fetchRecord()){
    $deal_link_ga = get_redirect($coupon_view);
    $merchant_name = ucwords($coupon_view->get_field('brand.name'));
    $tags_deal = get_deal_tags($coupon_view);
    $deal_id = $coupon_view->get_field('id');
    $deal_link = BUZZR_URL.'/deals/'.$coupon_view->get_field('camp_link');
    $deal_name = $coupon_view->get_field('name');
    $deal_title = substr($deal_name,0,150);
    $image_list = get_image($coupon_view);
  ?>
      	<div id="latest_city_wrap_<?php echo $deal_id; ?>" class="deal">
            
            <div id="latest_city_image_wrap_<?php echo $deal_id; ?>" class="deal_image">
               <?php if($image_list != TRUE){ ?>
               <a <?php buzzr_follow(); ?> href="<?php echo $deal_link; ?>"><div class="image_filler_home"><p><?php echo $merchant_name;?></p></div></a>
               <?php }else{ ?>
               <a <?php buzzr_follow(); ?> href="<?php echo $deal_link; ?>"><img src="<?php echo $image_list; ?>" alt="<?php echo $tags_deal; ?>" /></a>
               <?php } ?>
            </div>
            <div id="latest_city_detail_wrap_<?php echo $deal_id; ?>" class="deal_detail">
            	<a <?php buzzr_follow(); ?> href="<?php echo $deal_link; ?>"><?php echo $deal_title; ?></a>
            </div>
        
        </div>
        
    <?php } ?>
	
	</div>
  	<!-- Coupons -->

  </div>
  <div class="grid_8 more_deals_local t4">
       	<p>Show more <a href="<?php echo BUZZR_URL.'/localoffers/'.$city_name; ?>">Deals in <?php echo ucwords($city_name); ?></a></p>
  </div>
  <div class="grid_8 more_deals_local t5">
       	<p>Show more <a href="<?php echo BUZZR_URL.'/localoffers/'.$city_name; ?>">Deals in <?php echo ucwords($city_name); ?></a></p>
  </div>
  <div class="grid_8 more_deals_local t6">
       	<p>Show more <a href="<?php echo  BUZZR_URL.'/coupons';?>">Coupons in <?php echo ucwords($city_name); ?></a></p>
  </div>
</div>
<!-- Local Deals End -->

<div class="clear"></div>

<!-- Top Users -->
<div id="top_users_wrap" class="grid_5 home_wrap">
	<h3>Top Users</h3>
	<div id="topusers"> 
	<?php
	$points = new Pod('points');
	$points->page = 1;
	$points->search = false;
	$points->findRecords("(login+registration+comments+deals+like_fb+feedback+vote+referral) DESC, p.modified ASC", 5);
	$i = 0;
	while($points->fetchRecord())
	{
	   $name = $points->get_field('user.name');
	   $name = explode(' ',$name);
	   $user[$i]['wp_id'] = $points->get_field('user.wp_user.ID');
	   $user[$i]['name'] = $name[0];
	   $user[$i]['slug'] = $points->get_field('user.slug');
	   $user[$i]['total_points'] = $points->get_field('login') + $points->get_field('registration') + $points->get_field('comments') + $points->get_field('deals') + $points->get_field('like_fb') + $points->get_field('feedback') + $points->get_field('vote') + $points->get_field('referral');
	   $user[$i]['modified'] = $points->get_field('modified');
	   $i++;
	}
	
	foreach($user as $val){ 
	?>
	<div id="user_wrap_<?php echo $val['wp_id']; ?>" class="users">
	  <div id="user_name_wrap_<?php echo $val['wp_id']; ?>" class="user_name"><?php echo get_avatar($val['wp_id'],'50'); ?></div>
	  <div id="user_points_wrap_<?php echo $val['wp_id']; ?>"  class="user_points"><a href="<?php echo BUZZR_URL.'/member/'.$val['slug']; ?>"><?php echo $val['name']; ?></a></br> <?php echo $val['total_points'];?> points</div>
	  <div class="clear"></div>
	</div>
	
	<?php } ?>
	<div id="getpoints">
		<a href="<?php echo BUZZR_URL.'/get-points'; ?>" id="getpoints">Get Points</a>
	</div>
	<div class="clear"></div>
	</div>
</div>
<!-- Top Users End -->

<!-- Featured Stores -->
<div id="featured_stores_wrap" class="grid_6 home_wrap">
	<h3>Featured Stores</h3>
	<div id="brands">
	<?php
	$featured_brands= new Pod('brand');
	$featured_brands->page = 1;
	$featured_brands->search = false;
	$featured_brands->findRecords('id DESC', 10, 't.featured = 1');
	while ($featured_brands->fetchRecord())
	{
		$brand_id = $featured_brands->get_field('id');
		$brand_name = $featured_brands->get_field('name');
		$brand_url =  $featured_brands->get_field('brandurl');
		$brand_link = BUZZR_URL.'/brands/'.$brand_url;
		$brand_logo = $featured_brands->get_field('logo');
		$logo_small = wp_get_attachment_image_src($brand_logo[0][ID],'thumbnail', false);
		$logo_small = $logo_small[0];
	?>

		<div id="featured_store_wrap_<?php echo $brand_id; ?>" class="brand_logo">
		  <a href="<?php echo $brand_link; ?>">
		  <?php if(!empty($brand_logo)){ ?>
		     <img src="<?php echo $logo_small; ?>" alt="<?php echo $brand_name; ?>" />
		  <?php } ?>
		  </a>
		</div>
	<?php } ?>
	  <div class="clear"></div>
    </div>
    
</div>
<!-- Featured Stores -->

<!-- Social Media -->
<div class="grid_5 home_wrap">
  <h3>Connect with us</h3>
  <div id="social">
    <iframe src="http://www.facebook.com/plugins/likebox.php?id=144168869348&amp;width=250&amp;connections=10&amp;stream=false&amp;header=false&amp;height=255" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:255px;" allowTransparency="true"></iframe>
  </div>
</div>
<!-- Social Media End -->
<div class="clear"></div>

<div id="categories" class="grid_16">

   <p>Nationwide Deals in: <a href="http://buzzr.in/c-accessories-offers">Accessories</a> | <a href="http://buzzr.in/c-apparel-and-shoes-offers">Apparel and Shoes</a> | <a href="http://buzzr.in/c-books-music-and-video-offers">Books, Music and Video</a> | <a href="http://buzzr.in/c-electronics-offers">Electronics</a> | <a href="http://buzzr.in/c-gifts-offers">Gifts</a> | <a href="http://buzzr.in/c-fashion-offers">Fashion</a> | <a href="http://buzzr.in/c-home-offers">Home</a> | <a href="http://buzzr.in/c-travel-offers">Travel</a></p>
   <p>Local Deals in: <a href="<?php echo 'http://buzzr.in/localoffers/'.strtolower($city_name).'/c-entertainment-offers';?>">Entertainment</a> | <a href="<?php echo 'http://buzzr.in/localoffers/'.strtolower($city_name).'/c-restaurants-clubs-offers';?>">Restaurants and Clubs</a> | <a href="<?php echo 'http://buzzr.in/localoffers/'.strtolower($city_name).'/c-health-and-beauty-offers';?>">Health and Beauty</a> | <a href="<?php echo 'http://buzzr.in/localoffers/'.strtolower($city_name).'/c-services-offers'; ?>">Services</a> | <a href="<?php echo 'http://buzzr.in/localoffers/'.strtolower($city_name).'/c-shopping-offers'; ?>">Shopping</a></p>
   
</div>
<div class="clear"></div>

<?php get_footer(); ?>